import {UPDATECITY} from "./mutation-types";
import Vue from 'vue'
export default {
  updateCityAsync ({ commit, state }, {city}) {
    if (!city.name) {//如果传进来的参数没有name属性，将state中默认的name: '北京',rN: 'bj'赋给city
      city.name = state.name
      city.rN = state.rN
    }
    return  Vue.prototype.$axios.get(`/movie/hot/?city=${city.rN}`).then((response) => {//传递rN参数发送请求，获取Hot.vue页面的数据，保存到city变量中
      let data = response.data
      console.log(data)
      let lists = data.data.returnValue
      console.log(lists)
      //模拟索引数据的id号
      lists.forEach((item, index) => {
        item.mID = index
      })
      city.data  = lists
      commit(UPDATECITY, { city })
    })
  }
}
